// @flow

export const USER_ID = 'USER_ID'

type Action = {
  type: string,
  id: string
}

export const saveUserId = (id: string) => {
  return {
    type: USER_ID,
    id
  }
}

const ACTION_HANDLERS = {
  [USER_ID]: (state, { id }: Action) => Object.assign({}, state, {
    userId: id
  })
}

type State = Object

const initialState = {
  userId: ''
}

export default function userIdReducer (state: State = initialState, action: Action) {
  const handler = ACTION_HANDLERS[action.type]

  return handler ? handler(state, action) : state
}
